package com.skyjing.toolsuitls.java.tools;

/**
 * Created by ShenZhen Sancochip gc on 2018/5/16.
 * 防止按钮短时间内快速点击
 */
public class DoubleClickUtils {
    private static long lastClickTime = 0;
    private final static int SPACE_TIME = 500;

    public synchronized static void isDoubleClick(DoubleClickListener listener) {
        long currentTime = System.currentTimeMillis();
        boolean isClick2;
        if (currentTime - lastClickTime >
                SPACE_TIME) {
            isClick2 = false;
            if (listener != null){
                listener.positive();
            }
        } else {
            isClick2 = true;
            if (listener != null){
                listener.negative();
            }
        }
        lastClickTime = currentTime;
//        return isClick2;
    }

    public interface DoubleClickListener{
        void positive();
        void negative();
    }
}
